<script setup lang="ts">
import { reactive, onMounted, onBeforeMount } from 'vue'
import { getDataList } from '@/api/develop/list'
import { useI18n } from '@/hooks/web/useI18n'
import { useLocaleStoreWithOut } from '@/store/modules/locale'
import { DataTableView } from '@/components/ListView'
import { useRouter } from 'vue-router'

defineOptions({
  name: 'ListShow'
})
const { t } = useI18n()
const { currentRoute } = useRouter()
const localeStore = useLocaleStoreWithOut()
const curLang = localeStore.getCurrentLocale.lang

const state = reactive({
  inParam: {
    listId: null,
    fromPath: '/Develop/ListManage',
    closeEmit: '',
    preview: false
  },
  listTitle: '',
  listDef: {} as any
})

onBeforeMount(() => {})

onMounted(async () => {
  //读取传入参数
  state.inParam.listId = currentRoute.value.query.listId as any
  const preview = currentRoute.value.query.preview as any
  state.inParam.preview = preview == 1

  const fromPath = currentRoute.value.query.fromPath as any
  if (fromPath) {
    state.inParam.fromPath = fromPath
  }
  const closeEmit = currentRoute.value.query.closeEmit as any
  if (closeEmit) {
    state.inParam.closeEmit = closeEmit
  }
  let listNameField = 'name'
  if (curLang == 'en') {
    listNameField = 'enName'
  } else if (curLang == 'zh_HK') {
    listNameField = 'hkName'
  }
  state.listDef = await getDataList(state.inParam.listId)
  state.listTitle = state.listDef[listNameField]
  console.log(t(''))
})
</script>
<template>
  <div class="listParent">
    <div v-if="state.listDef.listType == 0">
      <DataTableView :list-def="state.listDef" :preview="state.inParam.preview" />
    </div>
  </div>
</template>
<style lang="less" scoped>
.listParent {
  padding: 20px 10px 0 10px;
}
</style>
